<template>
  <router-view></router-view>
</template>

<script>

export default {
  name: "App",
  data() {
    return {
      header: {
        height: "50px",
      },
      aside: {
        width: "240px",
      },
      foot: {
        height: "40px",
        showFoot: false,
      },
      operMenu: "el-icon-s-fold", //el-icon-s-unfold
      showMenu: false,
      headNav:[],
      tabList: [],
      isClick:false,
      token:''
    };
  },
  created(){
    const token = localStorage.getItem('token');
    this.token = token;
    this.$router.push({ path: '/'});
    // if(!token){
    //   this.$router.push({ path: 'login'});
    // }else{
    //   this.checkToken();
    // }
  },
  // watch: {
  //   $route: {
  //     handler(val, oldval) {
  //       console.log(this.isClick)
  //       const obj = {
  //         name: val.name||'',
  //         path: val.path||'/',
  //         params: val.query||{},
  //         active: true,
  //       };
  //       if(!oldval||!oldval.name){
  //         this.openPage('/');
  //       }
  //       if(obj.name=='登录'||this.isClick){
  //         this.isClick = false
  //         return false;
  //       }
  //       if (!oldval||!oldval.name || oldval.name == "login") {
  //         obj.active = true;
  //       }
  //       let hasTab = false;
  //       for (let i in this.tabList) {
  //         const item = this.tabList[i];
  //         if (item.name == obj.name) {
  //           hasTab = true;
  //           item.active = true;
  //         } else {
  //           item.active = false;
  //         }
  //       }
  //       if (!hasTab&&obj.name) {
  //         this.tabList.push(obj);
  //       }
        
  //     },
  //     immediate: true,
  //     deep: true,
  //   },
  // },
  mounted() {

  },
  methods: {
    checkToken(){
      const self = this;
      const refreshToken = localStorage.getItem('refreshToken');
      //  return new Promise((resolve, reject) => {
        this.$request({url:'checkToken'}).then(res=>{
          if(res){
            this.$router.push({ path: '/'});
          }else{
            if(refreshToken&&refreshToken!==self.token){
              self.token = refreshToken;
              localStorage.setItem('token',refreshToken);
              self.checkToken();
            }else{
              this.$router.push({ path: 'login'});
            }
          }
        }).catch(error=>{
          this.$router.push({ path: 'login'});
          // reject(error)
        })
      //  })
    },
  },
};
</script>

<style lang="scss">
// 引入全局样式
@import "@/assets/style/common.scss";
@import "@/assets/style/iconfont.scss";
.el-dropdown {
  & > span {
    color: #fff;
    cursor: pointer;
  }
}
</style>
